package com.kkb.shopcenter.controller;


import com.github.pagehelper.PageInfo;
import com.kkb.shopcenter.api.TemplateInfoService;
import com.kkb.shopcenter.common.common.HttpResult;
import com.kkb.shopcenter.common.pojo.TemplateInfo;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class TemplateController {

    @Reference
    private TemplateInfoService templateService;

    /**
     * 获取模板列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getTemplateList")
    public HttpResult getTemplateList(@RequestParam(value="page",defaultValue="1")int pageNo, @RequestParam(value="pageSize",defaultValue="10")int pageSize){

        PageInfo<TemplateInfo> templates = templateService.getTemplate( pageNo+1, pageSize);
        return HttpResult.success(templates);
    }

    /**
     * 关联品牌
     * @param templateInfo
     * @return
     */
    @PostMapping("/relatedBrand")
    public HttpResult templateRelateBrand(@RequestBody TemplateInfo templateInfo){
        int result = templateService.updateTemplateInfo(templateInfo);
        return HttpResult.success(result);
    }

    /**
     * 关联属性
     * @param templateInfo
     * @return
     */
    @PostMapping("/relatedAttribute")
    public HttpResult templateRelateAttr(@RequestBody TemplateInfo templateInfo){
        int result = templateService.updateTemplateInfo(templateInfo);
        return HttpResult.success(result);
    }

    /**
     * 获取品牌和属性
     * @param id
     * @return
     */
    @GetMapping("/getBrandsAndAttr")
    public HttpResult getBrandsAndAttr(Long id){
        TemplateInfo templateInfo=templateService.getBrandsAndAttr(id);
        return HttpResult.success(templateInfo);
    }


}
